const postcss = require("postcss");
module.exports = postcss.plugin("postcss-uni-px2rpx", (options) => {
  options = {
    ...{
      rate: 2,
      except: /Px/g,
    },
    ...options,
  };
  return (root) => {
    root.walkDecls((decl) => {
      decl.value = decl.value.replace(/(\d+)px/g, (math, px) => {
        return px * options.rate + "rpx";
      });
      decl.value = decl.value.replace(options.except, "px");
    });
  };
});
